package designpattern.d16;


/**
 * Created By  醉美柳舞之众星捧月
 *
 * @author songx
 * @date 2020/2/20 15:04
 */
public class ApplicationContext {

    private Alert alert;
    private AlertRule alertRule;
    private Notification notification;

    public Alert getAlert() {
        return alert;
    }

    public void initializeBeans() {
        alert = new Alert();
        alertRule = new AlertRule();
        notification = new Notification();
        alert.addAlertHandler(new TpsAlertHandler(alertRule, notification));
        alert.addAlertHandler(new ErrorAlertHandler(alertRule, notification));
        alert.addAlertHandler(new TimeoutAlertHandler(alertRule, notification));
    }

    private static final ApplicationContext INSTANCE = new ApplicationContext();

    public ApplicationContext() {
        INSTANCE.initializeBeans();
    }

    public static ApplicationContext getInstance() {
        return INSTANCE;
    }
}
